package com.hxy.springboot06.config;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.hxy.springboot06.servlet.HelloServlet;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.FilterRegistration;
import javax.servlet.Servlet;
import javax.sql.DataSource;
import java.util.Arrays;

@SpringBootConfiguration
public class SPConfig implements WebMvcConfigurer{
//    @Bean
//    public WebMvcConfigurer webMvcConfigurer(){
//        return new WebMvcConfigurer() {
//            @Override
//            public void addInterceptors(InterceptorRegistry registry) {
//                registry.addInterceptor(new LoginInterceptor())
//                        .addPathPatterns("/**")
//                        .excludePathPatterns("/","/login","/js/**","/fonts/**","/images/**","/css/**");
//            }
//        };
//    }
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource dataSource(){
        DruidDataSource druidDataSource=new DruidDataSource();
        return druidDataSource;
    }
//    @Bean
//    public ServletRegistrationBean<StatViewServlet> myservlet(){
//        StatViewServlet statViewServlet=new StatViewServlet();
//        return new ServletRegistrationBean(statViewServlet,"/druid/*");
//    }
//    @Bean
//    public FilterRegistrationBean myFilter(){
//        WebStatFilter myFilter=new WebStatFilter();
//        FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean(myFilter);
//        filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
//        filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
//        return filterRegistrationBean;
//    }
}
